package com.bianyuanren.v4.controller.city;

import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.system.domain.SysCity;
import com.bianyuanren.system.domain.SysDistrict;
import com.bianyuanren.system.service.ISysCityService;
import com.bianyuanren.system.service.ISysDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/api/city")
public class ApiCityController extends BaseController {

    @Autowired
    private ISysCityService sysCityService;

    @Autowired
    private ISysDistrictService sysDistrictService;

    /**
     * 通过国家获取省份
     */
    @PostMapping("/countryCity")
    @ResponseBody
    public AjaxResult CountryCity(Long countryId)
    {
        startPage();
        List<SysCity> list = sysCityService.selectCountryCityList(countryId);
        return AjaxResult.success(list);
    }

    /**
     * 通过省份获取城市
     */
    @PostMapping("/districtCity")
    @ResponseBody
    public AjaxResult districtCity(Long provinceId)
    {
        startPage();
        List<SysDistrict> list = sysDistrictService.apiDistrictList(provinceId);
        return AjaxResult.success(list);
    }
}
